/*Filename: scf-samples.doPaper: Unemployment and the Distribution of LiquidityAuthors: Zachary Bethune, Guillaume RocheteauContact: bethune@rice.eduLast Modified: 8/22/23Purpose: download and clean 1993-2013 waves of Survey of Consumer Finances to produce sample data*/clearclear matrixclear matacd "/Users/zbethune/Dropbox/Projects/WP/br-unemp/code/replication_file/empirical_data/do_files" set maxvar 6000set more offlocal x=1998cd ".././raw_data"while `x'<=2013{	***********************************************************************************************************************	* Load Data 	***********************************************************************************************************************	clear	use scf_raw_`x'.dta	gen year=`x'		***********************************************************************************************************************	* Implicates and case IDs	***********************************************************************************************************************	gen imp=Y1-YY1*10	gen id=YY1		gen id2=string(id)+string(year)	destring id2, replace	***********************************************************************************************************************	* Weights 	***********************************************************************************************************************	gen weight=X42001		***********************************************************************************************************************	* CPI 	***********************************************************************************************************************	gen cpi=1.0	replace cpi=1.43081 if year==1995	replace cpi=1.33777 if year==1998	replace cpi=1.23126 if year==2001	replace cpi=1.15435 if year==2004	replace cpi=1.05167 if year==2007	replace cpi=0.93604 if year==2013	***********************************************************************************************************************	*Demographic Variables 	***********************************************************************************************************************	*Age	gen age = X14	drop if age<25	drop if age>65	***********************************************************************************************************************	* Income Variables (all at an coded to calculate an annual flow)	***********************************************************************************************************************	*Total family income in 2003 (See itemized valued below)	gen total_incomeIRS=0	replace total_incomeIRS=X5729 if X5729>0	replace total_incomeIRS=total_incomeIRS*cpi	***********************************************************************************************************************	* Asset Variables 	***********************************************************************************************************************	*Value of farm	gen farm_value=X513+X526	replace farm_value=farm_value*cpi	*Value of mobile home/site	gen mobile_home_value = X604+X614+X623	replace mobile_home_value=mobile_home_value*cpi	*Value of home	gen home_value = X716	replace home_value=home_value*cpi	gen home_debt = X805+X905+X1005+X1044+X1108+X1119+X1130+X1215+X1219+X1136+X8401	replace home_debt=home_debt*cpi	gen home_equity = home_value-home_debt	replace home_equity=home_equity		*HELOC	gen heloc=0	replace heloc=1 if X1103==1 | X1114==1 | X1125==1	gen heloc_pos=0	replace heloc_pos=1 if X7141>0 & heloc==1	replace heloc_pos=1 if X7142>0 & heloc==1	replace heloc_pos=1 if X7143>0 & heloc==1		*Cash out refinance	gen cashout=0	replace cashout=1 if X7137==2 | X7137==3		*Home equity usage	gen he_usage=0	replace he_usage=1 if heloc_pos==1 | cashout==1		*Value of land contracts	gen land_contract=0	if `x'<=2007{		replace land_contract = X1409+X1509+X1609-X1417-X1517-X1617+X1619+X8402-X1621-X8404	}	if `x'==2010{		replace land_contract = X1409+X1509-X1417-X1517+X1619+X8402-X1621-X8404	}	if `x'>=2013{		replace land_contract = X1310+X1329+X1339+X8495-X1342-X8498	}	replace land_contract=land_contract*cpi	*Value of other real estate	gen real_estate_other1 = 0	replace real_estate_other1 = X1706*(X1705/10000) if X1706>0	gen real_estate_other2 = 0	replace real_estate_other2 = X1806*(X1805/10000) if X1806>0	gen real_estate_debt1 = X1715*(X1705/10000)	gen real_estate_debt2 = X1815*(X1805/10000)	gen real_estate_equity1 = real_estate_other1-real_estate_debt1	gen real_estate_equity2 = real_estate_other2-real_estate_debt2	gen real_estate_other4=X2002+X8406	gen real_estate_debt4=X2006+X8410	gen real_estate_equity4 = real_estate_other4-real_estate_debt4	gen real_estate_other5=X2012+X8416	gen real_estate_debt5=X2016+X8420	gen real_estate_equity5 = real_estate_other5-real_estate_debt5	replace real_estate_other1=real_estate_other1*cpi	replace real_estate_other2=real_estate_other2*cpi	replace real_estate_other4=real_estate_other4*cpi	replace real_estate_other5=real_estate_other5*cpi	replace real_estate_debt1=real_estate_debt1*cpi	replace real_estate_debt2=real_estate_debt2*cpi	replace real_estate_debt4=real_estate_debt4*cpi	replace real_estate_debt5=real_estate_debt5*cpi	replace real_estate_equity1=real_estate_equity1*cpi	replace real_estate_equity2=real_estate_equity2*cpi	replace real_estate_equity4=real_estate_equity4*cpi	replace real_estate_equity5=real_estate_equity5*cpi		gen real_estate_value = real_estate_other1+real_estate_other2+real_estate_other4+real_estate_other5	gen real_estate_debt = real_estate_debt1+real_estate_debt2+real_estate_debt4+real_estate_debt5	gen real_estate_equity = real_estate_value-real_estate_debt	replace real_estate_equity = real_estate_equity	gen property_value = farm_value+mobile_home_value+land_contract+real_estate_value+home_value	gen property_equity = home_equity+real_estate_equity+land_contract	*Businesses 	gen business_net_worth = X3124+X3224 	replace business_net_worth = business_net_worth-X3126 if X3127==4 | X3127==5	replace business_net_worth = business_net_worth-X3226 if X3227==4 | X3227==5	replace business_net_worth = business_net_worth+X3129 if X3129>0	replace business_net_worth = business_net_worth+X3229 if X3229>0	replace business_net_worth = business_net_worth+X3335 if X3335>0	replace business_net_worth = business_net_worth+X3408 if X3408>0	replace business_net_worth = business_net_worth+X3412 if X3412>0	replace business_net_worth = business_net_worth+X3416 if X3416>0	replace business_net_worth = business_net_worth+X3420 if X3420>0	replace business_net_worth = business_net_worth+X3428 if X3428>0	replace business_net_worth=business_net_worth*cpi		* Vehicles	gen vehicle_value = X8166+X8167+X8168+X8188+X2506+X2606+X2623+X8435	replace vehicle_value=vehicle_value*cpi	gen vehicle_debt = X2218+X2318+X2418+X7169+X2422+X8430+X2424+X8432+X2519+X2619+X2625+X8437	replace vehicle_debt=vehicle_debt*cpi	gen vehicle_equity=vehicle_value-vehicle_debt	replace vehicle_equity = vehicle_equity	*Checking accounts total	gen checking=0	replace checking=X3506 if X3506>0	replace checking=checking + X3510 if X3510>0	replace checking=checking + X3514 if X3514>0	replace checking=checking + X3518 if X3518>0	replace checking=checking + X3522 if X3522>0	replace checking=checking + X3526 if X3526>0	replace checking=checking + X3529 if X3529>0	replace checking=checking + X8446 if X8446>0 & !missing(X8446)	replace checking=checking*cpi	*Retirement Accounts by household member	gen retirement_own=0	gen retirement_spouse=0	gen retirement_other=0	if `x'<2004{		replace retirement_own=X3610 if X3610>0		replace retirement_spouse=X3620 if X3620>0		replace retirement_other=X3630 if X3630>0		}	if `x'>=2004{		replace retirement_own=X6551 if X6551>0		replace retirement_own=retirement_own + X6552 if X6552>0		replace retirement_own=retirement_own + X6553 if X6553>0		replace retirement_own=retirement_own + X6554 if X6554>0		replace retirement_spouse=X6559 if X6559>0		replace retirement_spouse=retirement_spouse + X6560 if X6560>0		replace retirement_spouse=retirement_spouse + X6561 if X6561>0		replace retirement_spouse=retirement_spouse + X6562 if X6562>0		replace retirement_other=X6567 if X6567>0		replace retirement_other=retirement_other + X6568 if X6568>0		replace retirement_other=retirement_other + X6569 if X6569>0		replace retirement_other=retirement_other + X6570 if X6570>0		}	replace retirement_own=retirement_own*cpi	replace retirement_spouse=retirement_spouse*cpi	replace retirement_other=retirement_other*cpi	gen retirement = retirement_own+retirement_spouse+retirement_other		*Retirement Withdrawl	if `x'>=2004{		gen retirement_withdrawl=0		replace retirement_withdrawl=1 if X6557==1 | X6565==1 | X6573==1	}	*Retirement Accounts with stocks	gen retirement_stocks=0	if `x'<2004{		replace retirement_stocks = retirement if X3631==1		replace retirement_stocks = retirement*(1/3) if X3631==4		replace retirement_stocks = retirement*(1/2) if X3631==5 | X3631==6	}	if `x'>=2004{		replace retirement_stocks = retirement_own if X6555==1		replace retirement_stocks = retirement_own*(X6556/10000) if X6555==3 		replace retirement_stocks = retirement_stocks + retirement_spouse if X6563==1		replace retirement_stocks = retirement_stocks + retirement_spouse*(X6564/10000) if X6563==3		replace retirement_stocks = retirement_stocks + retirement_other if X6571==1		replace retirement_stocks = retirement_stocks + retirement_other*(X6572/10000) if X6571==3	}	gen retirement_bonds = retirement - retirement_stocks	*CDs	gen CDs=0	replace CDs=X3721 if X3721>0 & (X7620==1 | X7620==2 | X7620==3 | X7620==4)	replace CDs=CDs*cpi		*Saving/MMDAs	gen savings=0	if `x'<2004{		replace savings=X3804 if X3804>0 & (X7622==1 | X7622==2 | X7622==3 | X7622==4)		replace savings=savings + X3807 if X3807>0 & (X7624==1 | X7624==2 | X7624==3 | X7624==4)		replace savings=savings + X3810 if X3810>0 & (X7626==1 | X7626==2 | X7626==3 | X7626==4)		replace savings=savings + X3813 if X3813>0 & (X7628==1 | X7628==2 | X7628==3 | X7628==4)		replace savings=savings + X3816 if X3816>0 & (X7630==1 | X7630==2 | X7630==3 | X7630==4)		replace savings=savings + X3818 if X3818>0		replace savings=savings + X8448 if X8448>0 & !missing(X8448)	}		if `x'>=2004{		replace savings=X3730 if X3730>0 & (X3731==1 | X3731==2 | X3731==3 | X3731==4) & (X3732!=2)		replace savings=savings + X3736 if X3736>0 & (X3737==1 | X3737==2 | X3737==3 | X3737==4) & (X3738!=2)		replace savings=savings + X3742 if X3742>0 & (X3743==1 | X3743==2 | X3743==3 | X3743==4) & (X3744!=2)		replace savings=savings + X3748 if X3748>0 & (X3749==1 | X3749==2 | X3749==3 | X3749==4) & (X3750!=2)		replace savings=savings + X3754 if X3754>0 & (X3755==1 | X3755==2 | X3755==3 | X3755==4) & (X3756!=2)		replace savings=savings + X3760 if X3760>0 & (X3761==1 | X3761==2 | X3761==3 | X3761==4) & (X3762!=2)		replace savings=savings + X3765 if X3765>0		replace savings=savings + X8473 if X8473>0 & !missing(X8473)	}	replace savings=savings*cpi	*Mututal Funds	gen mutualfunds_stocks=0	replace mutualfunds_stocks=X3822 if X3822>0	replace mutualfunds_stocks=mutualfunds_stocks + 0.5*(X3830) if X3830>0	replace mutualfunds_stocks=mutualfunds_stocks*cpi	gen mutualfunds_debt=0	replace mutualfunds_debt=X3824 if X3824>0	replace mutualfunds_debt=mutualfunds_debt + X3826 if X3826>0	replace mutualfunds_debt=mutualfunds_debt + X3828 if X3828>0	replace mutualfunds_debt=mutualfunds_debt + 0.5*X3830 if X3830>0	if `x'>=2004{		replace mutualfunds_debt=mutualfunds_debt + X7787 if X7787>0	}	replace mutualfunds_debt=mutualfunds_debt*cpi	*Other bonds (market value, including government bonds)	gen bonds_other=0	replace bonds_other=X3902 if X3902>0	replace bonds_other=bonds_other + X7635 if X7635>0	replace bonds_other=bonds_other + X7636 if X7636>0	replace bonds_other=bonds_other + X7637 if X7637>0	replace bonds_other=bonds_other + X7638 if X7638>0	replace bonds_other=bonds_other + X7639 if X7639>0	replace bonds_other=bonds_other + X6706 if X6706>0	replace bonds_other=bonds_other*cpi			*Publicly Traded Stock and Brokerage Accounts (**includes stock held in company currently or formerly employed.)	gen stock=0	replace stock=X3915 if X3915>0	*adjust for foreign stocks*	replace stock=stock-X7641 if X7641>0 	replace stock=stock*cpi		*Brokerage Accounts	gen brokerage_cash=0	*cash or call accounts with broker*	replace brokerage_cash=X3930 if X3930>0 	replace brokerage_cash=brokerage_cash*cpi			gen brokerage_margin=0	*margin loans at brokerage*	replace brokerage_margin=X3932 if X3932>0 	replace brokerage_margin=brokerage_margin*cpi		*Update stocks to subtract margin loans	replace stock=stock-brokerage_margin		*Annuities, trusts, investment accounts	gen annuities=0	gen annuities_stocks=0	if `x'<1998{		replace annuities=X3942 if X3942>0		replace annuities_stocks=annuities if X3947==1		replace annuities_stocks=annuities*(1/2) if X3947==5	}	if (1998<=`x' & `x'<2004){		replace annuities=X6820 if X6820>0		replace annuities_stocks=annuities if X6826==1		replace annuities_stocks=annuities*(1/2) if X6826==5		replace annuities=annuities+X6835 if X6835>0		replace annuities_stocks = annuities_stocks + X6835 if X6841==1		replace annuities_stocks = annuities_stocks + X6835*(1/2) if X6841==5	}	if `x'>=2004{		replace annuities=X6577 if X6577>0		replace annuities_stocks=annuities if X6581==1		replace annuities_stocks=annuities*(X6582/100000) if X6581==3		replace annuities = annuities+X6587 if X6587>0		replace annuities_stocks = annuities_stocks + X6587 if X6587>0 & X6591==1		replace annuities_stocks = annuities_stocks + X6587*(X6592/10000) if X6587>0 & X6591==3	}	replace annuities=annuities*cpi	replace annuities_stocks=annuities_stocks*cpi		*Pensions	gen pensions=0	if `x'<2004{		*first pension account, head		gen lump_sum=0		replace lump_sum=1 if X4213==3 | X4213==6		gen pay_now=0		replace pay_now=1 if X4213==1		gen pay_later=0		replace pay_later=1 if X4213==2				replace pensions=X4214 if lump_sum==1				replace pensions=X4214 if X7691==8 & pay_later==1		replace pensions=(X4214/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==6 & pay_later==1		replace pensions=(X4214*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==1 & pay_later==1		replace pensions=(X4214*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==2 & pay_later==1		replace pensions=(X4214*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==3 & pay_later==1		replace pensions=(X4214*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==4 & pay_later==1		replace pensions=(X4214*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==5 & pay_later==1		replace pensions=(X4214*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==11 & pay_later==1		replace pensions=(X4214*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7691==12 & pay_later==1				replace pensions=X4214 if X7691==8 & pay_now==1		replace pensions=(X4214/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==6 & pay_now==1		replace pensions=(X4214*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==1 & pay_now==1		replace pensions=(X4214*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==2 & pay_now==1		replace pensions=(X4214*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==3 & pay_now==1		replace pensions=(X4214*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==4 & pay_now==1		replace pensions=(X4214*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==5 & pay_now==1		replace pensions=(X4214*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==11 & pay_now==1		replace pensions=(X4214*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7691==12 & pay_now==1				drop lump_sum pay_now pay_later				*second pension account, head		gen lump_sum=0		replace lump_sum=1 if X4313==3 | X4313==6		gen pay_now=0		replace pay_now=1 if X4313==1		gen pay_later=0		replace pay_later=1 if X4313==2				replace pensions=pensions+X4314 if lump_sum==1				replace pensions=pensions+X4314 if X7692==8 & pay_later==1		replace pensions=pensions+(X4314/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==6 & pay_later==1		replace pensions=pensions+(X4314*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==1 & pay_later==1		replace pensions=pensions+(X4314*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==2 & pay_later==1		replace pensions=pensions+(X4314*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==3 & pay_later==1		replace pensions=pensions+(X4314*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==4 & pay_later==1		replace pensions=pensions+(X4314*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==5 & pay_later==1		replace pensions=pensions+(X4314*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==11 & pay_later==1		replace pensions=pensions+(X4314*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7692==12 & pay_later==1				replace pensions=pensions+X4314 if X7692==8 & pay_now==1		replace pensions=pensions+(X4314/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==6 & pay_now==1		replace pensions=pensions+(X4314*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==1 & pay_now==1		replace pensions=pensions+(X4314*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==2 & pay_now==1		replace pensions=pensions+(X4314*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==3 & pay_now==1		replace pensions=pensions+(X4314*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==4 & pay_now==1		replace pensions=pensions+(X4314*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==5 & pay_now==1		replace pensions=pensions+(X4314*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==11 & pay_now==1		replace pensions=pensions+(X4314*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7692==12 & pay_now==1				drop lump_sum pay_now pay_later					*first pension account, spouse		gen lump_sum=0		replace lump_sum=1 if X4813==3 | X4813==6		gen pay_now=0		replace pay_now=1 if X4813==1		gen pay_later=0		replace pay_later=1 if X4813==2				replace pensions=pensions+X4814 if lump_sum==1				replace pensions=pensions+X4814 if X7718==8 & pay_later==1		replace pensions=pensions+(X4814/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==6 & pay_later==1		replace pensions=pensions+(X4814*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==1 & pay_later==1		replace pensions=pensions+(X4814*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==2 & pay_later==1		replace pensions=pensions+(X4814*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==3 & pay_later==1		replace pensions=pensions+(X4814*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==4 & pay_later==1		replace pensions=pensions+(X4814*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==5 & pay_later==1		replace pensions=pensions+(X4814*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==11 & pay_later==1		replace pensions=pensions+(X4814*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7718==12 & pay_later==1				replace pensions=pensions+X4814 if X7718==8 & pay_now==1		replace pensions=pensions+(X4814/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==6 & pay_now==1		replace pensions=pensions+(X4814*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==1 & pay_now==1		replace pensions=pensions+(X4814*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==2 & pay_now==1		replace pensions=pensions+(X4814*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==3 & pay_now==1		replace pensions=pensions+(X4814*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==4 & pay_now==1		replace pensions=pensions+(X4814*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==5 & pay_now==1		replace pensions=pensions+(X4814*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==11 & pay_now==1		replace pensions=pensions+(X4814*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7718==12 & pay_now==1				drop lump_sum pay_now pay_later				*second pension account, spouse		gen lump_sum=0		replace lump_sum=1 if X4913==3 | X4913==6		gen pay_now=0		replace pay_now=1 if X4913==1		gen pay_later=0		replace pay_later=1 if X4913==2				replace pensions=pensions+X4914 if lump_sum==1				replace pensions=pensions+X4914 if X7719==8 & pay_later==1		replace pensions=pensions+(X4914/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==6 & pay_later==1		replace pensions=pensions+(X4914*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==1 & pay_later==1		replace pensions=pensions+(X4914*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==2 & pay_later==1		replace pensions=pensions+(X4914*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==3 & pay_later==1		replace pensions=pensions+(X4914*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==4 & pay_later==1		replace pensions=pensions+(X4914*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==5 & pay_later==1		replace pensions=pensions+(X4914*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==11 & pay_later==1		replace pensions=pensions+(X4914*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X7719==12 & pay_later==1				replace pensions=pensions+X4914 if X7719==8 & pay_now==1		replace pensions=pensions+(X4914/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==6 & pay_now==1		replace pensions=pensions+(X4914*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==1 & pay_now==1		replace pensions=pensions+(X4914*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==2 & pay_now==1		replace pensions=pensions+(X4914*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==3 & pay_now==1		replace pensions=pensions+(X4914*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==4 & pay_now==1		replace pensions=pensions+(X4914*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==5 & pay_now==1		replace pensions=pensions+(X4914*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==11 & pay_now==1		replace pensions=pensions+(X4914*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X7719==12 & pay_now==1				drop lump_sum pay_now pay_later				replace pensions=pensions-X4229-X4329-X4429-X4829-X4929-X5029		replace pensions=pensions*cpi	}		if `x'>=2004{		*first pension account, head		gen lump_sum=0		replace lump_sum=1 if X11022==1		replace lump_sum=1 if X11018==1 & X11019==0		gen pay_now=0		replace pay_now=1 if X11022==2		replace pay_now=1 if X11018==2 & X11019==0		gen pay_later=0		replace pay_later=1 if X11022==3		replace pay_later=1 if X11018==3 & X11019==0				replace pensions=X11023 if X11023>0 & lump_sum==1		replace pensions=X11023 if X11024==8 & pay_later==1		replace pensions=(X11023/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==6 & pay_later==1		replace pensions=(X11023*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==1 & pay_later==1		replace pensions=(X11023*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==2 & pay_later==1		replace pensions=(X11023*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==3 & pay_later==1		replace pensions=(X11023*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==4 & pay_later==1		replace pensions=(X11023*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==5 & pay_later==1		replace pensions=(X11023*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==11 & pay_later==1		replace pensions=(X11023*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==12 & pay_later==1		replace pensions=(X11023*24/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11024==31 & pay_later==1		replace pensions=X11023 if X11024==8 & pay_now==1		replace pensions=(X11023/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==6 & pay_now==1		replace pensions=(X11023*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==1 & pay_now==1		replace pensions=(X11023*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==2 & pay_now==1		replace pensions=(X11023*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==3 & pay_now==1		replace pensions=(X11023*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==4 & pay_now==1		replace pensions=(X11023*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==5 & pay_now==1		replace pensions=(X11023*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==11 & pay_now==1		replace pensions=(X11023*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==12 & pay_now==1		replace pensions=(X11023*24/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11024==31 & pay_now==1					drop lump_sum pay_now pay_later				*second pension account, head		gen lump_sum=0		replace lump_sum=1 if X11122==1		replace lump_sum=1 if X11118==1 & X11119==0		gen pay_now=0		replace pay_now=1 if X11122==2		replace pay_now=1 if X11118==2 & X11119==0		gen pay_later=0		replace pay_later=1 if X11122==3		replace pay_later=1 if X11118==3 & X11119==0				replace pensions=pensions + X11123 if X11123>0 & lump_sum==1		replace pensions=pensions + X11123 if X11124==8 & pay_later==1		replace pensions=pensions + (X11123/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==6 & pay_later==1		replace pensions=pensions + (X11123*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==1 & pay_later==1		replace pensions=pensions + (X11123*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==2 & pay_later==1		replace pensions=pensions + (X11123*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==3 & pay_later==1		replace pensions=pensions + (X11123*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==4 & pay_later==1		replace pensions=pensions + (X11123*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==5 & pay_later==1		replace pensions=pensions + (X11123*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==11 & pay_later==1		replace pensions=pensions + (X11123*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==12 & pay_later==1		replace pensions=pensions + (X11123*24/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11124==31 & pay_later==1		replace pensions=pensions + X11123 if X11124==8 & pay_now==1		replace pensions=pensions + (X11123/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==6 & pay_now==1		replace pensions=pensions + (X11123*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==1 & pay_now==1		replace pensions=pensions + (X11123*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==2 & pay_now==1		replace pensions=pensions + (X11123*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==3 & pay_now==1		replace pensions=pensions + (X11123*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==4 & pay_now==1		replace pensions=pensions + (X11123*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==5 & pay_now==1		replace pensions=pensions + (X11123*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==11 & pay_now==1		replace pensions=pensions + (X11123*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==12 & pay_now==1		replace pensions=pensions + (X11123*24/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11124==31 & pay_now==1					drop lump_sum pay_now pay_later				*first pension account, spouse		gen lump_sum=0		replace lump_sum=1 if X11322==1		replace lump_sum=1 if X11318==1 & X11319==0		gen pay_now=0		replace pay_now=1 if X11322==2		replace pay_now=1 if X11318==2 & X11319==0		gen pay_later=0		replace pay_later=1 if X11322==3		replace pay_later=1 if X11318==3 & X11319==0				replace pensions=pensions + X11323 if X11323>0 & lump_sum==1		replace pensions=pensions + X11323 if X11324==8 & pay_later==1		replace pensions=pensions + (X11323/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==6 & pay_later==1		replace pensions=pensions + (X11323*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==1 & pay_later==1		replace pensions=pensions + (X11323*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==2 & pay_later==1		replace pensions=pensions + (X11323*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==3 & pay_later==1		replace pensions=pensions + (X11323*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==4 & pay_later==1		replace pensions=pensions + (X11323*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==5 & pay_later==1		replace pensions=pensions + (X11323*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==11 & pay_later==1		replace pensions=pensions + (X11323*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==12 & pay_later==1		replace pensions=pensions + (X11323*24/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11324==31 & pay_later==1		replace pensions=pensions + X11323 if X11324==8 & pay_now==1		replace pensions=pensions + (X11323/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==6 & pay_now==1		replace pensions=pensions + (X11323*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==1 & pay_now==1		replace pensions=pensions + (X11323*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==2 & pay_now==1		replace pensions=pensions + (X11323*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==3 & pay_now==1		replace pensions=pensions + (X11323*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==4 & pay_now==1		replace pensions=pensions + (X11323*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==5 & pay_now==1		replace pensions=pensions + (X11323*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==11 & pay_now==1		replace pensions=pensions + (X11323*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==12 & pay_now==1		replace pensions=pensions + (X11323*24/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11324==31 & pay_now==1					drop lump_sum pay_now pay_later		*second pension account, spouse		gen lump_sum=0		replace lump_sum=1 if X11422==1		replace lump_sum=1 if X11418==1 & X11419==0		gen pay_now=0		replace pay_now=1 if X11422==2		replace pay_now=1 if X11418==2 & X11419==0		gen pay_later=0		replace pay_later=1 if X11422==3		replace pay_later=1 if X11418==3 & X11419==0				replace pensions=pensions + X11423 if X11423>0 & lump_sum==1		replace pensions=pensions + X11423 if X11424==8 & pay_later==1		replace pensions=pensions + (X11423/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==6 & pay_later==1		replace pensions=pensions + (X11423*365/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==1 & pay_later==1		replace pensions=pensions + (X11423*52/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==2 & pay_later==1		replace pensions=pensions + (X11423*26/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==3 & pay_later==1		replace pensions=pensions + (X11423*12/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==4 & pay_later==1		replace pensions=pensions + (X11423*4/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==5 & pay_later==1		replace pensions=pensions + (X11423*2/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==11 & pay_later==1		replace pensions=pensions + (X11423*6/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==12 & pay_later==1		replace pensions=pensions + (X11423*24/0.02)*((1.02^(79-65+1)-1)/1.02^(79-65))*(1/1.02^(65-age)) if X11424==31 & pay_later==1		replace pensions=pensions + X11423 if X11424==8 & pay_now==1		replace pensions=pensions + (X11423/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==6 & pay_now==1		replace pensions=pensions + (X11423*365/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==1 & pay_now==1		replace pensions=pensions + (X11423*52/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==2 & pay_now==1		replace pensions=pensions + (X11423*26/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==3 & pay_now==1		replace pensions=pensions + (X11423*12/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==4 & pay_now==1		replace pensions=pensions + (X11423*4/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==5 & pay_now==1		replace pensions=pensions + (X11423*2/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==11 & pay_now==1		replace pensions=pensions + (X11423*6/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==12 & pay_now==1		replace pensions=pensions + (X11423*24/0.02)*((1.02^(79-age+1)-1)/1.02^(79-age)) if X11424==31 & pay_now==1					drop lump_sum pay_now pay_later				replace pensions=pensions-X11027-X11127-X11327-X11427		replace pensions=pensions*cpi				*Penson withdrawl (through borrowing)		gen pension_withdrawl=0		replace pension_withdrawl=1 if X11026==1 | X11126==1 | X11326==1 | X11436==1		}			***********************************************************************************************************************	* Main set of variables used	***********************************************************************************************************************			*Liquid assets and assets to income (In baseline I use TOTAL INCOME reported directly from IRS Line 22, 2003), liquid assets as zero maturity	gen liquid=0	replace liquid=checking + savings + brokerage_cash	gen liquid_income=liquid/total_incomeIRS		*Illiquid financial assets (equity only), also include half of pensions (can't separate) and value of own businesses	gen illiquid_fs=0	replace illiquid_fs = retirement_stocks + mutualfunds_stocks + stock + annuities_stocks + 0.5*pensions + business_net_worth	replace illiquid_fs=0 if illiquid_fs<0	gen illiquid_fs_income = illiquid_fs/total_incomeIRS		*Illiquid financial assets (debt only), also include half of pensions (can't separate)	gen illiquid_fb=0	replace illiquid_fb = retirement_bonds + mutualfunds_debt + CDs + bonds_other + annuities - annuities_stocks + 0.5*pensions	replace illiquid_fb=0 if illiquid_fb<0	gen illiquid_fb_income = illiquid_fb/total_incomeIRS		*Illiquid consumer durable equity (housing, other real estate, and vehicles)	gen illiquid_h = vehicle_equity + property_equity	replace illiquid_h=0 if illiquid_h<0	gen illiquid_h_income = illiquid_h/total_incomeIRS			*Illiquid financial assets (stocks and bonds)	gen illiquid_f = illiquid_fs+illiquid_fb	gen illiquid_f_income = illiquid_f/total_incomeIRS		*Illiquid financial assets (stocks and bonds) and consumer durable equity	gen illiquid = illiquid_f + illiquid_h	gen illiquid_income = illiquid/total_incomeIRS		*Total household net worth	gen wealth = liquid+illiquid	gen wealth_income = wealth/total_incomeIRS	  	*Windsorize top of wealths and wealths to income at 99%-tile	sum liquid [w=weight/5], detail	local tH = r(p99)	replace liquid = `tH' if liquid>`tH'		sum liquid_income [w=weight/5], detail	local tH = r(p99)	replace liquid_income = `tH' if liquid_income>`tH'	sum illiquid_fs [w=weight/5], detail	local tH = r(p99)	replace illiquid_fs = `tH' if illiquid_fs>`tH'	sum illiquid_fs_income [w=weight/5], detail	local tH = r(p99)	replace illiquid_fs_income = `tH' if illiquid_fs_income>`tH'		sum illiquid_fb [w=weight/5], detail	local tH = r(p99)	replace illiquid_fb = `tH' if illiquid_fb>`tH'	sum illiquid_fb_income [w=weight/5], detail	local tH = r(p99)	replace illiquid_fb_income = `tH' if illiquid_fb_income>`tH'		sum illiquid_h [w=weight/5], detail	local tH = r(p99)	replace illiquid_h = `tH' if illiquid_h>`tH'	sum illiquid_h_income [w=weight/5], detail	local tH = r(p99)	replace illiquid_h_income = `tH' if illiquid_h_income>`tH'		sum illiquid_f [w=weight/5], detail	local tH = r(p99)	replace illiquid_f = `tH' if illiquid_f>`tH'	sum illiquid_f_income [w=weight/5], detail	local tH = r(p99)	replace illiquid_f_income = `tH' if illiquid_f_income>`tH'		sum illiquid [w=weight/5], detail	local tH = r(p99)	replace illiquid = `tH' if illiquid>`tH'	sum illiquid_income [w=weight/5], detail	local tH = r(p99)	replace illiquid_income = `tH' if illiquid_income>`tH'				sum wealth [w=weight/5], detail	local tH = r(p99)	replace wealth = `tH' if wealth>`tH'	sum wealth_income [w=weight/5], detail	local tH = r(p99)	replace wealth_income = `tH' if wealth_income>`tH'		sum total_incomeIRS [w=weight/5], detail	local tH = r(p99)	gen income = total_incomeIRS	replace income = `tH' if total_incomeIRS>`tH'	*Portfolio shares	gen liquid_share = liquid/wealth	gen illiquid_fb_share = illiquid_fb/wealth	gen illiquid_fs_share = illiquid_fs/wealth	gen illiquid_f_share = illiquid_f/wealth	gen illiquid_h_share = illiquid_h/wealth	gen illiquid_share = illiquid/wealth		***********************************************************************************************************************	***********************************************************************************************************************	drop J* X* Y*	*Save as Stata dataset	if `x'==1998{		save scf-sample-data, replace	}	if `x'>1998{		append using scf-sample-data		save scf-sample-data, replace	}	local x=`x'+3}